<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">节目管理</h1>
</div>
<div class="wrapper-md">
<div class="row">

 <div class="col-sm-2" >
   <!-- 左边菜单-->

   <div style=" overflow-y:auto; overflow-x:auto;  height:600px;">
     <ul id="treeDemo" class="ztree"></ul>
</div>


 </div>

 <div class="col-sm-10">
  <div class="panel panel-default">
    <div class="panel-heading">
      节目管理
    </div>
    <div  ng-controller="myTableCtrl">
   <div class="row">

 <div class="col-sm-6" >
 <div class="panel-heading">

<a ui-sref="app.movie.programEdit"><button class="btn btn-default btn-sm "><i class="fa fa-plus fa-lg"></i>&nbsp; 新增</button></a>
<a href="javascript:void(0);"  onclick="goEdit();"><button class="btn btn-default btn-sm "><i class="fa fa-edit fa-lg"></i>&nbsp; 编辑</button></a>
<a ui-sref="app.movie.programEdit"><button class="btn btn-default btn-sm "><i class="fa fa-trash-o fa-lg"></i>&nbsp; 删除</button></a>
<!--隐藏域-->
<input type="hidden" id ="optIds" name="optIds">


</div>
 </div>


 </div>
      <table id="myTable" class="table table-striped m-b-none">
      </table>


    
    </div>
  </div>
  </div>

  </div>

</div>










<script type="text/javascript">



function goEdit(){
  var optIds = $('#optIds').val();
  if(''==optIds){
       top.layer.msg('请至少选择一项');
       return false;
  }
  if(optIds.indexOf(",") != -1){
    top.layer.msg('编辑只能选择一项');
    return false;
  }
   window.location.href = '#/app/movie/program/edit';

}


function checkOne(){
  var optIds = '';
  $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
   if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
$('#optIds').val(optIds);

  console.log($('#optIds').val());
}




app.controller('myTableCtrl', function($scope, $http) {


});



var ztreeUrl  =  hostport + "/ihaibiCMP/cmp/HttpGetList.htmls?domainUrl="+cmpUrl+"program_class&query=delflag:0&sortby=classdisplayorder&order=asc&limit=9999&offset=0";

var dtUrl =  hostport + "/ihaibiCMP/cmp/HttpGetList.htmls?domainUrl="+cmpUrl+"program_info&query=delflag:0";

    $(document).ready(function(){

      //初始化ztree
    onloadZTree(ztreeUrl );//调用ztree-mine.js里的方法




 //初始化dataTable
     var table =  $('#myTable').DataTable({
            ajax: {
                url: dtUrl,
                dataSrc: ""
            },
         deferRender:true,
         Processing:true,
          buttons: [
        {
            extend: 'collection',
            text: 'Export',
            buttons: [ 'csv-flash', 'xls-flash', 'pdf-flash' ]
        }
    ],
            //默认最后一列（最后更新时间）降序排列
            order: [[3, "desc"]],
         
            //行创建完成后回调
            rowCallback: function (row, data, index) {
               
            },
                    aoColumns: [
                    { data : "Id",
                    title: "<input type='checkbox' id='allChecked' name='allChecked' />",
                  orderable: false , 
              render : function(data, type, full, meta) {
            return '<input type="checkbox" value="'+ data + '" name="ids" onclick="checkOne()"/>';
           }},
         { data: "Id",
            title: "ID"
          },
         { data: "ProgramTitle" ,
            title: "标题"
       },
            { data: "ProgramAuthor"  ,
              title: "作者" },
         
         { data: "ProgramIsAudited" ,
           title: "审核状态",
                    render: function (data, type, row, meta) {
                        if(row.ProgramIsAudited==0){
                          return "<i style='color:#2e8ded;' title='已审核' class='fa fa-check-square-o fa-lg'></i>"; 
                      }else{
                        return "<i  title='未审核' class='fa fa-remove fa-lg'></i>";
                      }
                    }},
         { data: "UpdateTime"   ,

         title: "更新时间",
                    render: function (data, type, row, meta) {

                        return getDateTime(data);
                    }}
     ],
            columnDefs: [
          
                {
                    targets: 6,
                    data: null,
                    title: "显示",
                    render: function (data, type, row, meta) {
                        var href = '';
                          if(row.ProgramDisplayOnPc==1){
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('pc',0,"
                              + row.Id
                              + ")>";
                          href += "<i style='color:#2e8ded;' title='PC' class='fa fa-laptop fa-lg'></i></a>";
                          
                          }else{
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('pc',1,"
                              + row.Id
                              + ")>";
                          href += "<i  title='PC' class='fa fa-laptop fa-lg'></i></a>";
                          }
                          if(row.ProgramDisplayOnPhone==1){
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('phone',0,"
                              + row.Id
                              + ")>";
                          href += "<i style='color:#2e8ded;' title='Phone' class='fa fa-phone fa-lg'></i></a>";
                          
                          }else{
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('phone',1,"
                              + row.Id
                              + ")>";
                          href += "<i  title='Phone' class='fa fa-phone fa-lg'></i></a>";
                          
                          }
                            
                          if(row.ProgramDisplayOnPad==1){
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('pad',0,"
                              + row.Id
                              + ")>";
                          href += "<i title='pad' style='color:#2e8ded;' class='fa fa-tablet fa-lg'></i></a>";
                          }else{
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('pad',1,"
                              + row.Id
                              + ")>";
                          href += "<i title='pad' class='fa fa-tablet fa-lg'></i></a>";
                          }
                          
                          
                          if(row.ProgramDisplayOnTv==1){

                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('tv',0,"
                              + row.Id
                              + ")>";
                          href += "<i title='pad' style='color:#2e8ded;' class='fa fa-tv fa-lg'></i></a>";
                          }else{
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=updateDisplay('tv',1,"
                              + row.Id
                              + ")>";
                          href += "<i title='pad' class='fa fa-tv fa-lg'></i></a>";
                          }
                      
                      return href;

                    }
                }
                ,
                {
                    targets: 7,
                    data: null,
                    title: "操作",
                    render: function (data, type, row, meta) {

                        var href = '';
                            href += "&nbsp;  <a href='javascript:void(0);' onclick=goEdit("
                              + row.Id
                              + ")>";
                          href += "<i  title='编辑' class='fa fa-edit fa-lg'></i></a>";
                          
                          href += "&nbsp;  <a href='javascript:void(0);' onclick=goDelete("
                              + row.Id
                              + ")>";
                          href += "<i  title='删除' class='fa fa-trash-o fa-lg'></i></a>";
                        
                      
                      return href;

                    }
                }


            ],
     drawCallback: function( settings ) {
         

           },

           initComplete:function(data){

//选中行
 $('#myTable tbody').on( 'click', 'tr', function () {
          
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
        
    } );

//全选、反选
$('#allChecked').on('click' , function(){
  console.log(this.checked);
  var boxes = document.getElementsByName("ids");
    for(i=0;i<boxes.length;i++){
                boxes[i].checked = this.checked;
    }
    var optIds ='';
    if(this.checked){
      $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
    }else{
  optIds='';
      }
      if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
      $('#optIds').val(optIds);
});




           },
            
     
            Paginate: true, 
           language:{
               url: 'vendor/jquery/datatables/Chinese.json'
          }

    });








　


});  





//修改是否展示状态
function updateDisplay(type,value,id){
  var info = '您确定';
  if(1==value){
    info+='打开';
  }else{
    info+='关闭';
  }
  
  if('pc'==type){
    info+='电脑端';
  }else if('phone'==type){
    info+='手机端';
  }else if('pad'==type){
    info+='pad端';
  }else if('tv'==type){
    info+='电视机端';
  }
  
  info+="显示吗？";
  
  top.layer.confirm(info, function(index){
    $.ajax({
      url : '<%=basePath%>program/updateDisplay.do',
      type : 'post',
      data : {
        type:type,
        programDisplay:value,
        programId : id
      },
      cache : false,
      success : function(data) {
        var msg = data.msg;
        top.layer.msg(msg);
        reloadobjList();
      }
    });
    top.layer.close(index);
  });
}

</script>



<style type="text/css">

.selected {
  background-color: #DFF0D8;
}
  
/* dataTables列内容居中 */
.table>tbody>tr>td{
        text-align:center;
}

/* dataTables表头居中 */
.table>thead:first-child>tr:first-child>th{
        text-align:center;
}
</style>